package com.analysis

//销售量随日变化趋势


import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions._

object DailySalesTrend {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .appName("Daily Sales Trend")
      .master("local[*]")
      .getOrCreate()

    val cleanedDF = spark.read.parquet("output/cleaned_data.parquet")

    val resultDF = cleanedDF
      .withColumn("Date", to_date(col("InvoiceDate")))
      .groupBy("Date")
      .agg(sum("Quantity").as("DailyQuantity"))
      .orderBy("Date")

    resultDF.write
      .mode("overwrite")
      .json("output/analysis_results/daily_sales_trend")

    resultDF.show(50)

    spark.stop()
  }
}